# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: xguo

import json
import pprint
import absl.flags as flags
import absl.app as app
from coin.flow.topic_record import TopicRecordReader, TopicRecord

flags.DEFINE_string('record_file', None, 'Specify record file.')

flags.DEFINE_boolean('big_json', False, 'json file.')


def main(_):
  reader = TopicRecordReader(flags.FLAGS.record_file)
  res = []
  for record in reader.read_records():
    if flags.FLAGS.big_json:
      res.append(json.loads(record.data.tobytes()))
    else:
      pprint.pprint(json.loads(record.data.tobytes()))

  if flags.FLAGS.big_json:
    print(json.dumps(res, indent=2))


if __name__ == '__main__':
  app.run(main)
